﻿using System.ComponentModel;

namespace Devonline.Identity;

/// <summary>
/// 用户上下文
/// </summary>
[DisplayName("用户上下文")]
public class UserContext
{
    public UserContext()
    {
        Roles = new List<RoleViewModel>();
        Groups = new List<GroupViewModel>();
        Resources = new List<ResourceViewModel>();
        ResourceTree = new List<ResourceViewModel>();
    }

    /// <summary>
    /// 是否系统用户
    /// </summary>
    public bool IsSystem => User?.Type == AuthorizeType.System;
    /// <summary>
    /// 是否超级管理员
    /// </summary>
    public bool IsAdministrator => User?.Type == AuthorizeType.Administrator;
    /// <summary>
    /// 是否开发者
    /// </summary>
    public bool IsDeveloper => User?.Type == AuthorizeType.Developer;
    /// <summary>
    /// 是否匿名用户
    /// </summary>
    public bool IsAnonymous => User?.Type == AuthorizeType.Anonymous;
    /// <summary>
    /// 用户编号
    /// </summary>
    public string? UserId => User?.Id;
    /// <summary>
    /// 用户名
    /// </summary>
    public string? UserName => User?.UserName;
    /// <summary>
    /// 用户
    /// </summary>
    public UserViewModel? User { get; init; }
    /// <summary>
    /// 级别
    /// </summary>
    public LevelViewModel? Level { get; init; }
    /// <summary>
    /// 角色
    /// </summary>
    public virtual ICollection<RoleViewModel> Roles { get; init; }
    /// <summary>
    /// 组织
    /// </summary>
    public virtual ICollection<GroupViewModel> Groups { get; init; }
    /// <summary>
    /// 用户授权资源列表
    /// </summary>
    public virtual ICollection<ResourceViewModel> Resources { get; init; }
    /// <summary>
    /// 用户授权资源树
    /// </summary>
    public virtual ICollection<ResourceViewModel> ResourceTree { get; init; }
}